import {Form,Button,message} from 'antd'
import  { useState } from 'react'
import { DiffOutlined } from '@ant-design/icons';
import { useNavigate } from 'react-router-dom';
import service from '../../../services/index'
import { useEffect } from 'react'
import AbsentTable from '../../../compoennts/studentAbsent/AbsentTable';
import Appraise from '../../../compoennts/Appraise/Appraise'
const dateFormat = 'YYYY-MM-DD';
function EstimateList(props) {
    const [data, setData] = useState([]);
    const [form] = Form.useForm(); //创建表单实例
    const [open, setOpen] = useState(false); //控制查看评价的抽屉\
    const [Rowdata, setRowdata] = useState({});

    // 点击查看触发，打开抽屉，查看评价
    const openDrawer = (data) => {
        setOpen(true)
        // console.log(data)
        setRowdata(data)
    }
    const onClose = () => {
        setOpen(false)
    }

    const columns = [
      {
        title: '序号',
        key: 'id',
        dataIndex: 'id',
        width: 150,
      },
      {
        title: '学生姓名',
        key: 'name',
        dataIndex: 'name',
        width: 150,
      },
      {
        title: '年级班级',
        key: 'className',
        dataIndex: 'className',
        width: 150,
      },
      {
        title: '评价类型',
        key: 'type',
        dataIndex: 'type',
        width: 150,
      },
      {
        title: '评价内容',
        key: 'content',
        dataIndex: 'content',
        width: 150,
      },
      {
        title: '分值',
        key: 'number',
        dataIndex: 'number',
        width: 150,
      },
      {
        title: '发布者',
        key: 'Publisher',
        width: 150,
        dataIndex: 'Publisher',
      },
      {
        title: '发布时间',
        key: 'createTime',
        dataIndex: 'createTime',
      },
      {
        title: '操作',
        width: 200,
        key: 'action',
        dataIndex: 'action',
        render: (_,record ,{id}) => {
         
              return (
                  <>
                      <a className='link_blue' onClick={() => handleDelteEst(id)}>删除</a>
                      <a className='link_blue' onClick={() => { openDrawer(record) }}>查看</a>
                  </>
              )
          
      }
  }
       
           
         
        
   
    ];
    const getEstimateList = async () => {
      let result = await service.EstimateService.getAllEstimate()
      setData(result.data)
      console.log(result)
  }
    useEffect(() => {
        //获取请假评价列表的函数
        
        getEstimateList()
    }, [JSON.stringify(data)])
    // 删除评价
    const handleDelteEst = async (id) => {
      let result = await service.EstimateService.deleteEstById(id)
      if (result.code === 200) {
        getEstimateList()
          message.success("删除成功")
      } else {
          message.success("删除失败")
      }
  }
//跳转发布评价页面
const navigator = useNavigate()
const handleEst = () => {
  navigator('/Review')
}
    
    



    return (
        < div >
          
          <Button type='primary' style={{ float: 'right' }} onClick={handleEst} ><DiffOutlined />
        发布评语
      </Button>
            {/* 表格区 */}
            < AbsentTable columns={columns} rowKey={record => record.id} data={data} >
            </AbsentTable >

            
            {/* 抽屉-查看评价 */}
            < Appraise open={open} onClose={onClose} data={Rowdata} />
            
        </div >
    );
}

export default EstimateList;